<template>
  <div class="selection" :style="{ background: `url(${imgbgc})`, 'background-size': '100% 100%' }">
    <div class="innerBox">
      <div class="content">
        <div class="contInner">
          <div class="title">分测验选择</div>
          <div class="selectBox">
            <el-checkbox border
              v-model="checkAll"
              :indeterminate="isIndeterminate"
              @change="handleCheckAllChange"
              >全选</el-checkbox
            >
            <el-checkbox-group
              v-model="selectOption"
              @change="handleCheckedChange"
            >
              <el-checkbox border v-for="item in options" :key="item.value" :label="item.value">{{
                item.name
              }}</el-checkbox>
            </el-checkbox-group>
          </div>
          <div class="btn">
            <el-button type="primary" @click="nextFn">下一步</el-button>
          </div>
        </div>
      </div>
      <div class="rightBox" v-if="personType=='child'">
        <img src="@/assets/images/c1.jpg" alt="">
      </div>
      <div class="rightBox" v-else>
        <img src="@/assets/images/p5.jpg" alt="">
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      imgbgc: require('../assets/images/pbgc.jpg'),
      personType: 'adult',
      checkAll: true,
      isIndeterminate: false,
      selectOption: ['1','2','3'],
      options: [
        {
          name:'双人关系测验',
          value: '1'
        },
        {
          name:'家庭或团体关系测验',
          value: '2'
        },
        {
          name:'社会情境测验',
          value: '3'
        }
      ]
    }
  },
  methods: {
    handleCheckAllChange(val) {
      this.selectOption = val ? ['1','2','3'] : []
      this.isIndeterminate = false
    },
    handleCheckedChange(value) {
      console.log(value)
      const checkedCount = value.length
      this.checkAll = checkedCount === this.options.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.options.length
    },
    nextFn() {
      // 根据选择的测验分类进行不同测验跳转
      this.selectOption = this.selectOption.sort()
      console.log(this.selectOption)
      if(this.selectOption.length>0) {
        this.$router.push({
          path: this.selectOption[0] === '1'?'/doubleText':(this.selectOption[0] === '2'?'/familyText':'/societyTextList'),
          query: {
            testType: this.selectOption.slice(1).join(',')
          }
        })
      } else {
        this.$message.info('请选择测验！')
      }
      
    }
  },
  mounted() {
    this.personType = sessionStorage.getItem('personType')
    if(this.personType == 'adult') {
      this.imgbgc = require('../assets/images/pbgc.jpg')
    } else {
      this.imgbgc = require('../assets/images/cbgc.jpg')
    }
  }
}
</script>

<style lang="scss" scoped>
.selection {
  height: calc(100vh - 200px);
  background: url(../assets/images/pbgc.jpg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  padding: 100px 140px;
  .innerBox {
    height: calc(100% - 80px);
    padding: 40px 20px;
    background-color: #ffffff;
    box-shadow: 35px 35px 50px 0px 
      rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
  }
  .content {
    width: 45%;
    // display: flex;
    // padding: 10px 80px 0px 100px;
    padding: 10px 5% 0 2%;
    .contInner {
      height: calc(100% - 50px);
    }
  }
  .rightBox {
    width: 55%;
    padding: 20px;
    // display: flex;
    // padding: 80px 150px 80px 0px;
    img {
      width: 95%;
      height: 100%;
    }
  }
  .title {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 40px;
    color: #009fb5;
  }
  .selectBox {
    margin-bottom: 20px;
  }
  .btn {
  }
}
</style>

<style lang="scss">
.selection {
  .el-checkbox-group {
    .el-checkbox {
      display: flex;
    }
  }
  .el-checkbox {
    width: 200px;
    margin-bottom: 20px;
  }
  .el-checkbox.is-bordered.is-checked {
    border-color: #009fb5;
  }
  .el-checkbox__input.is-indeterminate .el-checkbox__inner, .el-checkbox__input.is-checked .el-checkbox__inner {
    background-color: #009fb5;
    border-color: #009fb5;
  }
  .el-checkbox__input.is-checked+.el-checkbox__label {
    color: #009fb5;
  }
}
</style>